import 'package:ai/page/chat/chat_page.dart';
import 'package:ai/page/create/create_page.dart';
import 'package:ai/page/home_page.dart';
import 'package:ai/page/mine/mine_page.dart';
import 'package:auto_route/annotations.dart';
import 'package:flutter/material.dart';
import '../config/Config.dart';
import '../util/DeviceInfoUtils.dart';
import 'office/office_page.dart';

@RoutePage()
class MainPage extends StatefulWidget {
  const MainPage({super.key});

  @override
  State<MainPage> createState() => _MainPageState();
}

class _MainPageState extends State<MainPage> {
  late int _currentIndex = 0;
  late List<Widget> pages = [const HomePage(),const CreatePage(),const ChatPage(),const OfficePage(),const MinePage()];
  final PageController _pageController = PageController(
    initialPage: 0,
  );

  @override
  void initState() {
    super.initState();
    DeviceInfoUtils().initPlatformState();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: PageView(
        onPageChanged: (index){
          setState(() {
            _currentIndex = index;
          });
        },
        controller: _pageController,
          children: pages,
      ),
      bottomNavigationBar: BottomNavigationBar(
        backgroundColor: Colors.white,
        selectedItemColor: Config.color69f,
        unselectedItemColor: Config.color9,
        selectedLabelStyle: const TextStyle(
          fontWeight: FontWeight.bold,
        ),
        onTap: (index) {
          _pageController.jumpToPage(index);
          /// 修改底部菜单的索引之
          setState(() {
            _currentIndex = index;
          });
        },
        currentIndex: _currentIndex,
        type: BottomNavigationBarType.fixed,
        items: <BottomNavigationBarItem>[
          BottomNavigationBarItem(
            activeIcon: Image.asset(
              "asset/images/icon_home_checked.png",
              width: 24,
            ),
            icon: Image.asset(
              "asset/images/icon_home_unchecked.png",
              width: 24,
            ),
            label: "首页",
          ),
          BottomNavigationBarItem(
            activeIcon: Image.asset(
              "asset/images/icon_creator_checked.png",
              width: 24,
            ),
            icon: Image.asset(
              "asset/images/icon_creator_unchecked.png",
              width: 24,
            ),
            label: "创作",
          ),
          BottomNavigationBarItem(
            activeIcon: Image.asset(
              "asset/images/icon_work_checked.png",
              width: 24,
            ),
            icon: Image.asset(
              "asset/images/icon_work_unchecked.png",
              width: 24,
            ),
            label: "对话",
          ),
          BottomNavigationBarItem(
            activeIcon: Image.asset(
              "asset/images/icon_work_checked.png",
              width: 24,
            ),
            icon: Image.asset(
              "asset/images/icon_work_unchecked.png",
              width: 24,
            ),
            label: "办公",
          ),
          BottomNavigationBarItem(
            activeIcon: Image.asset(
              "asset/images/icon_mine_checked.png",
              width: 24,
            ),
            icon: Image.asset(
              "asset/images/icon_mine_unchecked.png",
              width: 24,
            ),
            label: "个人中心",
          ),
        ],
      ),
    );
  }
}
